package logic

import (
	"context"
	"jingdong_product/productrpc/productrpc"

	"jingdong_product/api/internal/svc"
	"jingdong_product/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProducUpdatetLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProducUpdatetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProducUpdatetLogic {
	return &ProducUpdatetLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProducUpdatetLogic) ProducUpdatet(req *types.ProducUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	update, err := l.svcCtx.ProductRpc.ProductUpdate(l.ctx, &productrpc.ProductUpdateRequest{
		Title:        req.Title,
		Content:      req.Content,
		ProductImage: req.ProductIMage,
		UserId:       req.UserId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Data:    update,
		Code:    200,
	}, nil
}
